#!/usr/ chuna
# -*- coding:utf-8 -*-
# Cross Validation 交叉验证
import numpy as np
from sklearn.model_selection import KFold
if __name__ == "__main__":
    # 数据
    X = np.array([[1, 2, 3, 4],
        [11, 12, 13, 14],
        [21, 22, 23, 24],
        [31, 32, 33, 34],
        [41, 42, 43, 44],
        [51, 52, 53, 54],
        [61, 62, 63, 64],
        [71, 72, 73, 74]
    ])
    Y = np.array([1, 1, 0, 0, 1, 1, 0, 0])
    # 拆分
    folder=KFold(n_splits=3,shuffle=False)
    for train_index,test_index in folder.split(X,Y):
        print("Train Index:",train_index)
        print("Test Index:",test_index)
        print("X_train:",X[train_index])
        print("X_test:",X[test_index])
        print("")

    folder = KFold(n_splits=3, random_state=0, shuffle=True)
    print("shuffle：是否在分割成批次之前将数据洗牌。")
    for train_index,test_index in folder.split(X,Y):
        print("Train Index:",train_index)
        print("Test Index:",test_index)
        print("X_train:",X[train_index])
        print("X_test:",X[test_index])
        print("")

